Imports System
Imports System.Data
Imports System.Collections
Imports System.Collections.Generic

Imports Framework

<Serializable(), CLSCompliant(True)> _
Partial Public Class CProduct
    Inherits SchemaAudit.CBaseDynamicAudited
    Implements IComparable(Of CProduct)

#Region "Constructors"
    'Public (Copy Constructor)
    Public Sub New(ByVal original as CProduct, target As CDataSrc)
        m_dataSrc = target
        m_productTypeId = original.ProductTypeId
        m_productSpeakerId = original.ProductSpeakerId
        m_productSpeaker2Id = original.ProductSpeaker2Id
        m_productLanguageId = original.ProductLanguageId
        m_productLocationId = original.ProductLocationId
        m_productBelongsToProductId = original.ProductBelongsToProductId
        m_productBelongsToSortOrder = original.ProductBelongsToSortOrder
        m_productName = original.ProductName
        m_productNameChineseSimplified = original.ProductNameChineseSimplified
        m_productNameChineseTraditional = original.ProductNameChineseTraditional
        m_productDescription = original.ProductDescription
        m_productDescriptionChineseSimplified = original.ProductDescriptionChineseSimplified
        m_productDescriptionChineseTraditional = original.ProductDescriptionChineseTraditional
        m_productKeywords = original.ProductKeywords
        m_productKeywordsChineseSimplified = original.ProductKeywordsChineseSimplified
        m_productKeywordsChineseTraditional = original.ProductKeywordsChineseTraditional
        m_productPaypalButtonId = original.ProductPaypalButtonId
        m_productImage = original.ProductImage
        m_productThumb = original.ProductThumb
        m_productTiny = original.ProductTiny
        m_productIsActive = original.ProductIsActive
        m_productScribeId = original.ProductScribeId
        m_productImageScribeId = original.ProductImageScribeId
        m_productTranscription = original.ProductTranscription
        m_productVimeoId = original.ProductVimeoId
        m_productYouTubeId = original.ProductYouTubeId
        m_productSmashwordsId = original.ProductSmashwordsId
        m_productAmazonId = original.ProductAmazonId
        m_productCSBookId = original.ProductCSBookId
        m_productCSBook2Id = original.ProductCSBook2Id
        m_productCSBook3Id = original.ProductCSBook3Id
        m_productNotesAsPlainText = original.ProductNotesAsPlainText
        m_productYouTubePlaylistId = original.ProductYouTubePlaylistId
        m_productVimeoChannelId = original.ProductVimeoChannelId
        m_productTranscriptionChineseSimplified = original.ProductTranscriptionChineseSimplified
        m_productTranscriptionChineseTraditional = original.ProductTranscriptionChineseTraditional
        m_productCreated = original.ProductCreated
    End Sub

    'Protected (Datareader/Dataset)
    Protected Sub New(ByVal dataSrc As CDataSrc, ByVal dr As IDataReader)
        MyBase.New(dataSrc, dr)
    End Sub
    Protected Sub New(ByVal dataSrc As CDataSrc, ByVal dr As DataRow)
        MyBase.New(dataSrc, dr)
    End Sub
#End Region

#Region "Default Values"
    Protected Overrides Sub InitValues_Auto()
        'Null-Equivalent values (except String.Empty, as nulls tend to be inconvenient for string types)
        m_productId = Integer.MinValue
        m_productTypeId = 0
        m_productSpeakerId = 0
        m_productSpeaker2Id = 0
        m_productLanguageId = 0
        m_productLocationId = 0
        m_productBelongsToProductId = Integer.MinValue
        m_productBelongsToSortOrder = Integer.MinValue
        m_productName = String.Empty
        m_productNameChineseSimplified = String.Empty
        m_productNameChineseTraditional = String.Empty
        m_productDescription = String.Empty
        m_productDescriptionChineseSimplified = String.Empty
        m_productDescriptionChineseTraditional = String.Empty
        m_productKeywords = String.Empty
        m_productKeywordsChineseSimplified = String.Empty
        m_productKeywordsChineseTraditional = String.Empty
        m_productPaypalButtonId = Integer.MinValue
        m_productImage = String.Empty
        m_productThumb = String.Empty
        m_productTiny = String.Empty
        m_productIsActive = False
        m_productScribeId = 0
        m_productImageScribeId = 0
        m_productTranscription = String.Empty
        m_productVimeoId = Integer.MinValue
        m_productYouTubeId = String.Empty
        m_productSmashwordsId = Integer.MinValue
        m_productAmazonId = String.Empty
        m_productCSBookId = Integer.MinValue
        m_productCSBook2Id = Integer.MinValue
        m_productCSBook3Id = Integer.MinValue
        m_productNotesAsPlainText = String.Empty
        m_productYouTubePlaylistId = String.Empty
        m_productVimeoChannelId = String.Empty
        m_productTranscriptionChineseSimplified = String.Empty
        m_productTranscriptionChineseTraditional = String.Empty
        m_productCreated = DateTime.MinValue
    End Sub
#End Region

#Region "Members"
    Protected m_productId As Integer
    Protected m_productTypeId As Byte
    Protected m_productSpeakerId As Byte
    Protected m_productSpeaker2Id As Byte
    Protected m_productLanguageId As Byte
    Protected m_productLocationId As Byte
    Protected m_productBelongsToProductId As Integer
    Protected m_productBelongsToSortOrder As Integer
    Protected m_productName As String
    Protected m_productNameChineseSimplified As String
    Protected m_productNameChineseTraditional As String
    Protected m_productDescription As String
    Protected m_productDescriptionChineseSimplified As String
    Protected m_productDescriptionChineseTraditional As String
    Protected m_productKeywords As String
    Protected m_productKeywordsChineseSimplified As String
    Protected m_productKeywordsChineseTraditional As String
    Protected m_productPaypalButtonId As Integer
    Protected m_productImage As String
    Protected m_productThumb As String
    Protected m_productTiny As String
    Protected m_productIsActive As Boolean
    Protected m_productScribeId As Byte
    Protected m_productImageScribeId As Byte
    Protected m_productTranscription As String
    Protected m_productVimeoId As Integer
    Protected m_productYouTubeId As String
    Protected m_productSmashwordsId As Integer
    Protected m_productAmazonId As String
    Protected m_productCSBookId As Integer
    Protected m_productCSBook2Id As Integer
    Protected m_productCSBook3Id As Integer
    Protected m_productNotesAsPlainText As String
    Protected m_productYouTubePlaylistId As String
    Protected m_productVimeoChannelId As String
    Protected m_productTranscriptionChineseSimplified As String
    Protected m_productTranscriptionChineseTraditional As String
    Protected m_productCreated As DateTime
#End Region

#Region "Properties - Column Values"
    'Primary Key Column (ReadOnly)
    Public ReadOnly Property [ProductId]() As Integer
        Get
            Return m_productId
        End Get
    End Property

    'Table Columns (Read/Write)
    Public Property [ProductTypeId]() As Byte
        Get
            Return m_productTypeId
        End Get
        Set(ByVal value As Byte)
            m_productTypeId = value
        End Set
    End Property
    Public Property [ProductSpeakerId]() As Byte
        Get
            Return m_productSpeakerId
        End Get
        Set(ByVal value As Byte)
            m_productSpeakerId = value
        End Set
    End Property
    Public Property [ProductSpeaker2Id]() As Byte
        Get
            Return m_productSpeaker2Id
        End Get
        Set(ByVal value As Byte)
            m_productSpeaker2Id = value
        End Set
    End Property
    Public Property [ProductLanguageId]() As Byte
        Get
            Return m_productLanguageId
        End Get
        Set(ByVal value As Byte)
            m_productLanguageId = value
        End Set
    End Property
    Public Property [ProductLocationId]() As Byte
        Get
            Return m_productLocationId
        End Get
        Set(ByVal value As Byte)
            m_productLocationId = value
        End Set
    End Property
    Public Property [ProductBelongsToProductId]() As Integer
        Get
            Return m_productBelongsToProductId
        End Get
        Set(ByVal value As Integer)
            m_productBelongsToProductId = value
        End Set
    End Property
    Public Property [ProductBelongsToSortOrder]() As Integer
        Get
            Return m_productBelongsToSortOrder
        End Get
        Set(ByVal value As Integer)
            m_productBelongsToSortOrder = value
        End Set
    End Property
    Public Property [ProductName]() As String
        Get
            Return m_productName
        End Get
        Set(ByVal value As String)
            m_productName = value
        End Set
    End Property
    Public Property [ProductNameChineseSimplified]() As String
        Get
            Return m_productNameChineseSimplified
        End Get
        Set(ByVal value As String)
            m_productNameChineseSimplified = value
        End Set
    End Property
    Public Property [ProductNameChineseTraditional]() As String
        Get
            Return m_productNameChineseTraditional
        End Get
        Set(ByVal value As String)
            m_productNameChineseTraditional = value
        End Set
    End Property
    Public Property [ProductDescription]() As String
        Get
            Return m_productDescription
        End Get
        Set(ByVal value As String)
            m_productDescription = value
        End Set
    End Property
    Public Property [ProductDescriptionChineseSimplified]() As String
        Get
            Return m_productDescriptionChineseSimplified
        End Get
        Set(ByVal value As String)
            m_productDescriptionChineseSimplified = value
        End Set
    End Property
    Public Property [ProductDescriptionChineseTraditional]() As String
        Get
            Return m_productDescriptionChineseTraditional
        End Get
        Set(ByVal value As String)
            m_productDescriptionChineseTraditional = value
        End Set
    End Property
    Public Property [ProductKeywords]() As String
        Get
            Return m_productKeywords
        End Get
        Set(ByVal value As String)
            m_productKeywords = value
        End Set
    End Property
    Public Property [ProductKeywordsChineseSimplified]() As String
        Get
            Return m_productKeywordsChineseSimplified
        End Get
        Set(ByVal value As String)
            m_productKeywordsChineseSimplified = value
        End Set
    End Property
    Public Property [ProductKeywordsChineseTraditional]() As String
        Get
            Return m_productKeywordsChineseTraditional
        End Get
        Set(ByVal value As String)
            m_productKeywordsChineseTraditional = value
        End Set
    End Property
    Public Property [ProductPaypalButtonId]() As Integer
        Get
            Return m_productPaypalButtonId
        End Get
        Set(ByVal value As Integer)
            m_productPaypalButtonId = value
        End Set
    End Property
    Public Property [ProductImage]() As String
        Get
            Return m_productImage
        End Get
        Set(ByVal value As String)
            m_productImage = value
        End Set
    End Property
    Public Property [ProductThumb]() As String
        Get
            Return m_productThumb
        End Get
        Set(ByVal value As String)
            m_productThumb = value
        End Set
    End Property
    Public Property [ProductTiny]() As String
        Get
            Return m_productTiny
        End Get
        Set(ByVal value As String)
            m_productTiny = value
        End Set
    End Property
    Public Property [ProductIsActive]() As Boolean
        Get
            Return m_productIsActive
        End Get
        Set(ByVal value As Boolean)
            m_productIsActive = value
        End Set
    End Property
    Public Property [ProductScribeId]() As Byte
        Get
            Return m_productScribeId
        End Get
        Set(ByVal value As Byte)
            m_productScribeId = value
        End Set
    End Property
    Public Property [ProductImageScribeId]() As Byte
        Get
            Return m_productImageScribeId
        End Get
        Set(ByVal value As Byte)
            m_productImageScribeId = value
        End Set
    End Property
    Public Property [ProductTranscription]() As String
        Get
            Return m_productTranscription
        End Get
        Set(ByVal value As String)
            m_productTranscription = value
        End Set
    End Property
    Public Property [ProductVimeoId]() As Integer
        Get
            Return m_productVimeoId
        End Get
        Set(ByVal value As Integer)
            m_productVimeoId = value
        End Set
    End Property
    Public Property [ProductYouTubeId]() As String
        Get
            Return m_productYouTubeId
        End Get
        Set(ByVal value As String)
            m_productYouTubeId = value
        End Set
    End Property
    Public Property [ProductSmashwordsId]() As Integer
        Get
            Return m_productSmashwordsId
        End Get
        Set(ByVal value As Integer)
            m_productSmashwordsId = value
        End Set
    End Property
    Public Property [ProductAmazonId]() As String
        Get
            Return m_productAmazonId
        End Get
        Set(ByVal value As String)
            m_productAmazonId = value
        End Set
    End Property
    Public Property [ProductCSBookId]() As Integer
        Get
            Return m_productCSBookId
        End Get
        Set(ByVal value As Integer)
            m_productCSBookId = value
        End Set
    End Property
    Public Property [ProductCSBook2Id]() As Integer
        Get
            Return m_productCSBook2Id
        End Get
        Set(ByVal value As Integer)
            m_productCSBook2Id = value
        End Set
    End Property
    Public Property [ProductCSBook3Id]() As Integer
        Get
            Return m_productCSBook3Id
        End Get
        Set(ByVal value As Integer)
            m_productCSBook3Id = value
        End Set
    End Property
    Public Property [ProductNotesAsPlainText]() As String
        Get
            Return m_productNotesAsPlainText
        End Get
        Set(ByVal value As String)
            m_productNotesAsPlainText = value
        End Set
    End Property
    Public Property [ProductYouTubePlaylistId]() As String
        Get
            Return m_productYouTubePlaylistId
        End Get
        Set(ByVal value As String)
            m_productYouTubePlaylistId = value
        End Set
    End Property
    Public Property [ProductVimeoChannelId]() As String
        Get
            Return m_productVimeoChannelId
        End Get
        Set(ByVal value As String)
            m_productVimeoChannelId = value
        End Set
    End Property
    Public Property [ProductTranscriptionChineseSimplified]() As String
        Get
            Return m_productTranscriptionChineseSimplified
        End Get
        Set(ByVal value As String)
            m_productTranscriptionChineseSimplified = value
        End Set
    End Property
    Public Property [ProductTranscriptionChineseTraditional]() As String
        Get
            Return m_productTranscriptionChineseTraditional
        End Get
        Set(ByVal value As String)
            m_productTranscriptionChineseTraditional = value
        End Set
    End Property
    Public Property [ProductCreated]() As DateTime
        Get
            Return m_productCreated
        End Get
        Set(ByVal value As DateTime)
            m_productCreated = value
        End Set
    End Property

    'View Columns (ReadOnly)

#End Region

#Region "MustOverride Methods"
    'Schema Information
    Public Const TABLE_NAME As String = "tblMcm_Products"
    Public Const VIEW_NAME As String  = ""          'Used to override Me.ViewName
    Public Const ORDER_BY_COLS As String = "ProductBelongsToSortOrder, ProductCreated DESC" 'See the CompareTo method below (Sql-based sorting should match In-Memory sorting)
    Public Const SORTING_COLUMN As String = "ProductBelongsToSortOrder"
    Public Overrides ReadOnly Property TableName() As String
        Get
            Return TABLE_NAME
        End Get
    End Property
    Protected Overrides ReadOnly Property OrderByColumns() As String
        Get
            Return ORDER_BY_COLS
        End Get
    End Property

    'CompareTo Interface (Default Sort Order)
    Public Function CompareTo(ByVal other As CProduct) As Integer Implements IComparable(Of CProduct).CompareTo
        Dim i As Integer = Me.ProductBelongsToSortOrder.CompareTo(other.ProductBelongsToSortOrder) 
        If 0 <> i Then Return i
        Return Me.ProductCreated.CompareTo(other.ProductCreated) *-1
    End Function

    'Primary Key Information
    Public Const PRIMARY_KEY_NAME As String = "ProductId"
    Protected Overrides ReadOnly Property InsertPrimaryKey() As Boolean
        Get
            Return False
        End Get
    End Property
    Protected Overrides ReadOnly Property PrimaryKeyName() As String
        Get
            Return PRIMARY_KEY_NAME
        End Get
    End Property
    Protected Overrides Property PrimaryKeyValue() As Object
        Get
            Return m_productId
        End Get
        Set(ByVal value As Object)
            m_productId = CType(Value, Integer)
        End Set
    End Property

    'Factory Methods - Object
    Protected Overrides Function MakeFrom(ByVal row As DataRow) As CBase
        Return New CProduct(Me.DataSrc, row)
    End Function
    Protected Overrides Function MakeFrom(ByVal dr As IDataReader) As CBase
        Return New CProduct(Me.DataSrc, dr)
    End Function
    
    'Factory Methods - List
    Protected Overrides Function MakeList() As IList
        Return New CProductList
    End Function
    Protected Overrides Function MakeList(ByVal capacity As Integer) As IList
        Return New CProductList(capacity)
    End Function

    'Convert from ADO to .Net
    Protected Overrides Sub ReadColumns(ByVal dr As IDataReader)
        m_productId = CAdoData.GetInt(dr, "ProductId")
        m_productTypeId = CAdoData.GetByte(dr, "ProductTypeId")
        m_productSpeakerId = CAdoData.GetByte(dr, "ProductSpeakerId")
        m_productSpeaker2Id = CAdoData.GetByte(dr, "ProductSpeaker2Id")
        m_productLanguageId = CAdoData.GetByte(dr, "ProductLanguageId")
        m_productLocationId = CAdoData.GetByte(dr, "ProductLocationId")
        m_productBelongsToProductId = CAdoData.GetInt(dr, "ProductBelongsToProductId")
        m_productBelongsToSortOrder = CAdoData.GetInt(dr, "ProductBelongsToSortOrder")
        m_productName = CAdoData.GetStr(dr, "ProductName")
        m_productNameChineseSimplified = CAdoData.GetStr(dr, "ProductNameChineseSimplified")
        m_productNameChineseTraditional = CAdoData.GetStr(dr, "ProductNameChineseTraditional")
        m_productDescription = CAdoData.GetStr(dr, "ProductDescription")
        m_productDescriptionChineseSimplified = CAdoData.GetStr(dr, "ProductDescriptionChineseSimplified")
        m_productDescriptionChineseTraditional = CAdoData.GetStr(dr, "ProductDescriptionChineseTraditional")
        m_productKeywords = CAdoData.GetStr(dr, "ProductKeywords")
        m_productKeywordsChineseSimplified = CAdoData.GetStr(dr, "ProductKeywordsChineseSimplified")
        m_productKeywordsChineseTraditional = CAdoData.GetStr(dr, "ProductKeywordsChineseTraditional")
        m_productPaypalButtonId = CAdoData.GetInt(dr, "ProductPaypalButtonId")
        m_productImage = CAdoData.GetStr(dr, "ProductImage")
        m_productThumb = CAdoData.GetStr(dr, "ProductThumb")
        m_productTiny = CAdoData.GetStr(dr, "ProductTiny")
        m_productIsActive = CAdoData.GetBool(dr, "ProductIsActive")
        m_productScribeId = CAdoData.GetByte(dr, "ProductScribeId")
        m_productImageScribeId = CAdoData.GetByte(dr, "ProductImageScribeId")
        m_productTranscription = CAdoData.GetStr(dr, "ProductTranscription")
        m_productVimeoId = CAdoData.GetInt(dr, "ProductVimeoId")
        m_productYouTubeId = CAdoData.GetStr(dr, "ProductYouTubeId")
        m_productSmashwordsId = CAdoData.GetInt(dr, "ProductSmashwordsId")
        m_productAmazonId = CAdoData.GetStr(dr, "ProductAmazonId")
        m_productCSBookId = CAdoData.GetInt(dr, "ProductCSBookId")
        m_productCSBook2Id = CAdoData.GetInt(dr, "ProductCSBook2Id")
        m_productCSBook3Id = CAdoData.GetInt(dr, "ProductCSBook3Id")
        m_productNotesAsPlainText = CAdoData.GetStr(dr, "ProductNotesAsPlainText")
        m_productYouTubePlaylistId = CAdoData.GetStr(dr, "ProductYouTubePlaylistId")
        m_productVimeoChannelId = CAdoData.GetStr(dr, "ProductVimeoChannelId")
        m_productTranscriptionChineseSimplified = CAdoData.GetStr(dr, "ProductTranscriptionChineseSimplified")
        m_productTranscriptionChineseTraditional = CAdoData.GetStr(dr, "ProductTranscriptionChineseTraditional")
        m_productCreated = CAdoData.GetDate(dr, "ProductCreated")
    End Sub
    Protected Overrides Sub ReadColumns(ByVal dr As DataRow)
        m_productId = CAdoData.GetInt(dr, "ProductId")
        m_productTypeId = CAdoData.GetByte(dr, "ProductTypeId")
        m_productSpeakerId = CAdoData.GetByte(dr, "ProductSpeakerId")
        m_productSpeaker2Id = CAdoData.GetByte(dr, "ProductSpeaker2Id")
        m_productLanguageId = CAdoData.GetByte(dr, "ProductLanguageId")
        m_productLocationId = CAdoData.GetByte(dr, "ProductLocationId")
        m_productBelongsToProductId = CAdoData.GetInt(dr, "ProductBelongsToProductId")
        m_productBelongsToSortOrder = CAdoData.GetInt(dr, "ProductBelongsToSortOrder")
        m_productName = CAdoData.GetStr(dr, "ProductName")
        m_productNameChineseSimplified = CAdoData.GetStr(dr, "ProductNameChineseSimplified")
        m_productNameChineseTraditional = CAdoData.GetStr(dr, "ProductNameChineseTraditional")
        m_productDescription = CAdoData.GetStr(dr, "ProductDescription")
        m_productDescriptionChineseSimplified = CAdoData.GetStr(dr, "ProductDescriptionChineseSimplified")
        m_productDescriptionChineseTraditional = CAdoData.GetStr(dr, "ProductDescriptionChineseTraditional")
        m_productKeywords = CAdoData.GetStr(dr, "ProductKeywords")
        m_productKeywordsChineseSimplified = CAdoData.GetStr(dr, "ProductKeywordsChineseSimplified")
        m_productKeywordsChineseTraditional = CAdoData.GetStr(dr, "ProductKeywordsChineseTraditional")
        m_productPaypalButtonId = CAdoData.GetInt(dr, "ProductPaypalButtonId")
        m_productImage = CAdoData.GetStr(dr, "ProductImage")
        m_productThumb = CAdoData.GetStr(dr, "ProductThumb")
        m_productTiny = CAdoData.GetStr(dr, "ProductTiny")
        m_productIsActive = CAdoData.GetBool(dr, "ProductIsActive")
        m_productScribeId = CAdoData.GetByte(dr, "ProductScribeId")
        m_productImageScribeId = CAdoData.GetByte(dr, "ProductImageScribeId")
        m_productTranscription = CAdoData.GetStr(dr, "ProductTranscription")
        m_productVimeoId = CAdoData.GetInt(dr, "ProductVimeoId")
        m_productYouTubeId = CAdoData.GetStr(dr, "ProductYouTubeId")
        m_productSmashwordsId = CAdoData.GetInt(dr, "ProductSmashwordsId")
        m_productAmazonId = CAdoData.GetStr(dr, "ProductAmazonId")
        m_productCSBookId = CAdoData.GetInt(dr, "ProductCSBookId")
        m_productCSBook2Id = CAdoData.GetInt(dr, "ProductCSBook2Id")
        m_productCSBook3Id = CAdoData.GetInt(dr, "ProductCSBook3Id")
        m_productNotesAsPlainText = CAdoData.GetStr(dr, "ProductNotesAsPlainText")
        m_productYouTubePlaylistId = CAdoData.GetStr(dr, "ProductYouTubePlaylistId")
        m_productVimeoChannelId = CAdoData.GetStr(dr, "ProductVimeoChannelId")
        m_productTranscriptionChineseSimplified = CAdoData.GetStr(dr, "ProductTranscriptionChineseSimplified")
        m_productTranscriptionChineseTraditional = CAdoData.GetStr(dr, "ProductTranscriptionChineseTraditional")
        m_productCreated = CAdoData.GetDate(dr, "ProductCreated")
    End Sub

    'Parameters for Insert/Update    
    Protected Overrides Function ColumnNameValues() As CNameValueList
        Dim data As New CNameValueList
        data.Add("ProductId", NullVal(m_productId))
        data.Add("ProductTypeId", NullVal(m_productTypeId))
        data.Add("ProductSpeakerId", NullVal(m_productSpeakerId))
        data.Add("ProductSpeaker2Id", NullVal(m_productSpeaker2Id))
        data.Add("ProductLanguageId", NullVal(m_productLanguageId))
        data.Add("ProductLocationId", NullVal(m_productLocationId))
        data.Add("ProductBelongsToProductId", NullVal(m_productBelongsToProductId))
        data.Add("ProductBelongsToSortOrder", NullVal(m_productBelongsToSortOrder))
        data.Add("ProductName", NullVal(m_productName))
        data.Add("ProductNameChineseSimplified", NullVal(m_productNameChineseSimplified))
        data.Add("ProductNameChineseTraditional", NullVal(m_productNameChineseTraditional))
        data.Add("ProductDescription", NullVal(m_productDescription))
        data.Add("ProductDescriptionChineseSimplified", NullVal(m_productDescriptionChineseSimplified))
        data.Add("ProductDescriptionChineseTraditional", NullVal(m_productDescriptionChineseTraditional))
        data.Add("ProductKeywords", NullVal(m_productKeywords))
        data.Add("ProductKeywordsChineseSimplified", NullVal(m_productKeywordsChineseSimplified))
        data.Add("ProductKeywordsChineseTraditional", NullVal(m_productKeywordsChineseTraditional))
        data.Add("ProductPaypalButtonId", NullVal(m_productPaypalButtonId))
        data.Add("ProductImage", NullVal(m_productImage))
        data.Add("ProductThumb", NullVal(m_productThumb))
        data.Add("ProductTiny", NullVal(m_productTiny))
        data.Add("ProductIsActive", NullVal(m_productIsActive))
        data.Add("ProductScribeId", NullVal(m_productScribeId))
        data.Add("ProductImageScribeId", NullVal(m_productImageScribeId))
        data.Add("ProductTranscription", NullVal(m_productTranscription))
        data.Add("ProductVimeoId", NullVal(m_productVimeoId))
        data.Add("ProductYouTubeId", NullVal(m_productYouTubeId))
        data.Add("ProductSmashwordsId", NullVal(m_productSmashwordsId))
        data.Add("ProductAmazonId", NullVal(m_productAmazonId))
        data.Add("ProductCSBookId", NullVal(m_productCSBookId))
        data.Add("ProductCSBook2Id", NullVal(m_productCSBook2Id))
        data.Add("ProductCSBook3Id", NullVal(m_productCSBook3Id))
        data.Add("ProductNotesAsPlainText", NullVal(m_productNotesAsPlainText))
        data.Add("ProductYouTubePlaylistId", NullVal(m_productYouTubePlaylistId))
        data.Add("ProductVimeoChannelId", NullVal(m_productVimeoChannelId))
        data.Add("ProductTranscriptionChineseSimplified", NullVal(m_productTranscriptionChineseSimplified))
        data.Add("ProductTranscriptionChineseTraditional", NullVal(m_productTranscriptionChineseTraditional))
        data.Add("ProductCreated", NullVal(m_productCreated))
        Return data
    End Function
#End Region

#Region "Queries - SelectAll/SelectWhere (inherited methods, cast only)"
    'Select Queries - Non-Paged
    Public Shadows Function SelectAll() As CProductList
        Return CType(MyBase.SelectAll(), CProductList)
    End Function
    Public Shadows Function SelectAll(ByVal orderBy As String) As CProductList
        Return CType(MyBase.SelectAll(orderBy), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal colName As String, ByVal sign As ESign, ByVal colValue As Object) As CProductList
        Return CType(MyBase.SelectWhere(colName, sign, colValue), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal where As CCriteria) As CProductList
        Return CType(MyBase.SelectWhere(where), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal where As CCriteriaList) As CProductList
        Return CType(MyBase.SelectWhere(where), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal where As CCriteriaList, ByVal tableNameOrJoinExpression As String) As CProductList
        Return CType(MyBase.SelectWhere(where, tableNameOrJoinExpression, Me.OrderByColumns), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal where As CCriteriaList, ByVal tableNameOrJoinExpression As String, ByVal orderBy As String) As CProductList
        Return CType(MyBase.SelectWhere(where, tableNameOrJoinExpression, orderBy), CProductList)
    End Function
    <Obsolete("Arbitrary where-clause is not necessary portable or safe from sql injection attacks. Consider using the parameterised query interfaces")> _
    Protected Shadows Function SelectWhere(ByVal unsafeWhereClause As String) As CProductList
        Return CType(MyBase.SelectWhere(unsafeWhereClause), CProductList)
    End Function
    Protected Shadows Function SelectById(ByVal productId As Integer) As CProductList
        Return CType(MyBase.SelectById(productId), CProductList)
    End Function
    Protected Shadows Function SelectByIds(ByVal ids As List(Of Integer)) As CProductList
        Return CType(MyBase.SelectByIds(ids), CProductList)
    End Function

    'Select Queries - Paged
    Public Shadows Function SelectAll(ByVal pi As CPagingInfo) As CProductList
        Return CType(MyBase.SelectAll(pi), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal pi As CPagingInfo, ByVal colName As String, ByVal sign As ESign, ByVal colValue As Object) As CProductList
        Return CType(MyBase.SelectWhere(pi, colName, sign, colValue), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal pi As CPagingInfo, ByVal criteria As CCriteria) As CProductList
        Return CType(MyBase.SelectWhere(pi, criteria), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal pi As CPagingInfo, ByVal criteria As CCriteriaList) As CProductList
        Return CType(MyBase.SelectWhere(pi, criteria), CProductList)
    End Function
    Protected Shadows Function SelectWhere(ByVal pi As CPagingInfo, ByVal criteria As CCriteriaList, ByVal tableViewOrJoinExpr As String) As CProductList
        Return CType(MyBase.SelectWhere(pi, criteria, tableViewOrJoinExpr), CProductList)
    End Function
    Protected Shadows Function SelectByIds(ByVal pi As CPagingInfo, ByVal ids As List(Of Integer)) As CProductList
        Return CType(MyBase.SelectByIds(pi, ids), CProductList)
    End Function

    'Select Queries - Transactional (Friend-scoped for use in cascade-deletes)
    Friend Shadows Function SelectAll(ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectAll(tx), CProductList)
    End Function
    Friend Shadows Function SelectWhere(ByVal columnName As String, columnValue As Object, ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectWhere(columnName, columnValue, tx), CProductList)
    End Function
    Friend Shadows Function SelectWhere(ByVal columnName As String, sign As ESign, columnValue As Object, ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectWhere(columnName, sign, columnValue, tx), CProductList)
    End Function
    Friend Shadows Function SelectWhere(ByVal criteria As CCriteria, ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectWhere(criteria, tx), CProductList)
    End Function
    Friend Shadows Function SelectWhere(ByVal criteria As CCriteriaList, ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectWhere(criteria, tx), CProductList)
    End Function
    Friend Shadows Function SelectWhere(ByVal criteria As CCriteriaList, ByVal tableOrJoin As String, ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectWhere(criteria, tableOrJoin, tx), CProductList)
    End Function
    Friend Shadows Function SelectWhere(ByVal criteria As CCriteriaList, ByVal tableOrJoin As String, ByVal orderBy As String, ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectWhere(criteria, tableOrJoin, orderBy, tx), CProductList)
    End Function
    Friend Shadows Function SelectById(ByVal productId As Integer, ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectById(productId, tx), CProductList)
    End Function
    Friend Shadows Function SelectByIds(ByVal ids As List(Of Integer), ByVal tx As IDbTransaction) As CProductList
        Return CType(MyBase.SelectByIds(ids, tx), CProductList)
    End Function
    
    'Select Queries - Stored Procedures
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal txOrNull As IDbTransaction) As CProductList
        Return CType(MyBase.MakeList(storedProcName,         txOrNull), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal params As Object(), ByVal txOrNull As IDbTransaction) As CProductList
        Return CType(MyBase.MakeList(storedProcName, params, txOrNull), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal params As CNameValueList, ByVal txOrNull As IDbTransaction) As CProductList
        Return CType(MyBase.MakeList(storedProcName, params, txOrNull), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal params As List(Of Object), ByVal txOrNull As IDbTransaction) As CProductList
        Return CType(MyBase.MakeList(storedProcName, params, txOrNull), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal param1 As Integer, ByVal txOrNull As IDbTransaction) As CProductList
        Return CType(MyBase.MakeList(storedProcName, param1, txOrNull), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal storedProcName As String, ByVal param1 As String, ByVal txOrNull As IDbTransaction) As CProductList
        Return CType(MyBase.MakeList(storedProcName, param1, txOrNull), CProductList)
    End Function

    'Query Results
    Protected Overloads Function MakeList(ByVal ds As DataSet) As CProductList
        Return CType(MyBase.MakeList(ds), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal dt As DataTable) As CProductList
        Return CType(MyBase.MakeList(dt), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal rows As DataRowCollection) As CProductList
        Return CType(MyBase.MakeList(rows), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal dr As IDataReader) As CProductList
        Return CType(MyBase.MakeList(dr), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal drOrDs As Object) As CProductList
        Return CType(MyBase.MakeList(drOrDs), CProductList)
    End Function
    Protected Overloads Function MakeList(ByVal gzip As Byte()) As CProductList
        Return CType(MyBase.MakeList(gzip), CProductList)
    End Function
#End Region

#Region "Queries - SelectBy[FK] (user-nominated fk/bool columns)"
    'Note: These methods should only be used for cascade-deletes, or initialising the cache. Use CProduct.Cache.GetBy... for reqular queries
    
    'Non-Paged
    Protected Function SelectByTypeId(ByVal productTypeId As Byte) As CProductList
        Return SelectWhere(new CCriteriaList("ProductTypeId", productTypeId))
    End Function
    Protected Function SelectBySpeakerId(ByVal productSpeakerId As Byte) As CProductList
        Return SelectWhere(new CCriteriaList("ProductSpeakerId", productSpeakerId))
    End Function
    Protected Function SelectBySpeaker2Id(ByVal productSpeaker2Id As Byte) As CProductList
        Return SelectWhere(new CCriteriaList("ProductSpeaker2Id", productSpeaker2Id))
    End Function
    Protected Function SelectByLanguageId(ByVal productLanguageId As Byte) As CProductList
        Return SelectWhere(new CCriteriaList("ProductLanguageId", productLanguageId))
    End Function
    Protected Function SelectByLocationId(ByVal productLocationId As Byte) As CProductList
        Return SelectWhere(new CCriteriaList("ProductLocationId", productLocationId))
    End Function
    Protected Function SelectByBelongsToProductId(ByVal productBelongsToProductId As Integer) As CProductList
        Return SelectWhere(new CCriteriaList("ProductBelongsToProductId", productBelongsToProductId))
    End Function
    Protected Function SelectByPaypalButtonId(ByVal productPaypalButtonId As Integer) As CProductList
        Return SelectWhere(new CCriteriaList("ProductPaypalButtonId", productPaypalButtonId))
    End Function
    Protected Function SelectByIsActive(ByVal productIsActive As Boolean) As CProductList
        Return SelectWhere(new CCriteriaList("ProductIsActive", productIsActive))
    End Function
    Protected Function SelectByScribeId(ByVal productScribeId As Byte) As CProductList
        Return SelectWhere(new CCriteriaList("ProductScribeId", productScribeId))
    End Function
    Protected Function SelectByImageScribeId(ByVal productImageScribeId As Byte) As CProductList
        Return SelectWhere(new CCriteriaList("ProductImageScribeId", productImageScribeId))
    End Function
    Protected Function SelectByVimeoId(ByVal productVimeoId As Integer) As CProductList
        Return SelectWhere(new CCriteriaList("ProductVimeoId", productVimeoId))
    End Function
    Protected Function SelectByYouTubeId(ByVal productYouTubeId As String) As CProductList
        Return SelectWhere(new CCriteriaList("ProductYouTubeId", productYouTubeId))
    End Function
    Protected Function SelectBySmashwordsId(ByVal productSmashwordsId As Integer) As CProductList
        Return SelectWhere(new CCriteriaList("ProductSmashwordsId", productSmashwordsId))
    End Function
    Protected Function SelectByAmazonId(ByVal productAmazonId As String) As CProductList
        Return SelectWhere(new CCriteriaList("ProductAmazonId", productAmazonId))
    End Function
    Protected Function SelectByCSBookId(ByVal productCSBookId As Integer) As CProductList
        Return SelectWhere(new CCriteriaList("ProductCSBookId", productCSBookId))
    End Function
    Protected Function SelectByCSBook2Id(ByVal productCSBook2Id As Integer) As CProductList
        Return SelectWhere(new CCriteriaList("ProductCSBook2Id", productCSBook2Id))
    End Function
    Protected Function SelectByCSBook3Id(ByVal productCSBook3Id As Integer) As CProductList
        Return SelectWhere(new CCriteriaList("ProductCSBook3Id", productCSBook3Id))
    End Function
    Protected Function SelectByYouTubePlaylistId(ByVal productYouTubePlaylistId As String) As CProductList
        Return SelectWhere(new CCriteriaList("ProductYouTubePlaylistId", productYouTubePlaylistId))
    End Function
    Protected Function SelectByVimeoChannelId(ByVal productVimeoChannelId As String) As CProductList
        Return SelectWhere(new CCriteriaList("ProductVimeoChannelId", productVimeoChannelId))
    End Function

    'Paged
    Protected Function SelectByTypeId(pi as CPagingInfo, ByVal productTypeId As Byte) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductTypeId", productTypeId))
    End Function
    Protected Function SelectBySpeakerId(pi as CPagingInfo, ByVal productSpeakerId As Byte) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductSpeakerId", productSpeakerId))
    End Function
    Protected Function SelectBySpeaker2Id(pi as CPagingInfo, ByVal productSpeaker2Id As Byte) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductSpeaker2Id", productSpeaker2Id))
    End Function
    Protected Function SelectByLanguageId(pi as CPagingInfo, ByVal productLanguageId As Byte) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductLanguageId", productLanguageId))
    End Function
    Protected Function SelectByLocationId(pi as CPagingInfo, ByVal productLocationId As Byte) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductLocationId", productLocationId))
    End Function
    Protected Function SelectByBelongsToProductId(pi as CPagingInfo, ByVal productBelongsToProductId As Integer) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductBelongsToProductId", productBelongsToProductId))
    End Function
    Protected Function SelectByPaypalButtonId(pi as CPagingInfo, ByVal productPaypalButtonId As Integer) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductPaypalButtonId", productPaypalButtonId))
    End Function
    Protected Function SelectByIsActive(pi as CPagingInfo, ByVal productIsActive As Boolean) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductIsActive", productIsActive))
    End Function
    Protected Function SelectByScribeId(pi as CPagingInfo, ByVal productScribeId As Byte) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductScribeId", productScribeId))
    End Function
    Protected Function SelectByImageScribeId(pi as CPagingInfo, ByVal productImageScribeId As Byte) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductImageScribeId", productImageScribeId))
    End Function
    Protected Function SelectByVimeoId(pi as CPagingInfo, ByVal productVimeoId As Integer) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductVimeoId", productVimeoId))
    End Function
    Protected Function SelectByYouTubeId(pi as CPagingInfo, ByVal productYouTubeId As String) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductYouTubeId", productYouTubeId))
    End Function
    Protected Function SelectBySmashwordsId(pi as CPagingInfo, ByVal productSmashwordsId As Integer) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductSmashwordsId", productSmashwordsId))
    End Function
    Protected Function SelectByAmazonId(pi as CPagingInfo, ByVal productAmazonId As String) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductAmazonId", productAmazonId))
    End Function
    Protected Function SelectByCSBookId(pi as CPagingInfo, ByVal productCSBookId As Integer) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductCSBookId", productCSBookId))
    End Function
    Protected Function SelectByCSBook2Id(pi as CPagingInfo, ByVal productCSBook2Id As Integer) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductCSBook2Id", productCSBook2Id))
    End Function
    Protected Function SelectByCSBook3Id(pi as CPagingInfo, ByVal productCSBook3Id As Integer) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductCSBook3Id", productCSBook3Id))
    End Function
    Protected Function SelectByYouTubePlaylistId(pi as CPagingInfo, ByVal productYouTubePlaylistId As String) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductYouTubePlaylistId", productYouTubePlaylistId))
    End Function
    Protected Function SelectByVimeoChannelId(pi as CPagingInfo, ByVal productVimeoChannelId As String) As CProductList
        Return SelectWhere(pi, New CCriteriaList("ProductVimeoChannelId", productVimeoChannelId))
    End Function

    'Count
    Protected Function SelectCountByTypeId(ByVal productTypeId As Byte) As Integer
        Return SelectCount(New CCriteriaList("ProductTypeId", productTypeId))
    End Function
    Protected Function SelectCountBySpeakerId(ByVal productSpeakerId As Byte) As Integer
        Return SelectCount(New CCriteriaList("ProductSpeakerId", productSpeakerId))
    End Function
    Protected Function SelectCountBySpeaker2Id(ByVal productSpeaker2Id As Byte) As Integer
        Return SelectCount(New CCriteriaList("ProductSpeaker2Id", productSpeaker2Id))
    End Function
    Protected Function SelectCountByLanguageId(ByVal productLanguageId As Byte) As Integer
        Return SelectCount(New CCriteriaList("ProductLanguageId", productLanguageId))
    End Function
    Protected Function SelectCountByLocationId(ByVal productLocationId As Byte) As Integer
        Return SelectCount(New CCriteriaList("ProductLocationId", productLocationId))
    End Function
    Protected Function SelectCountByBelongsToProductId(ByVal productBelongsToProductId As Integer) As Integer
        Return SelectCount(New CCriteriaList("ProductBelongsToProductId", productBelongsToProductId))
    End Function
    Protected Function SelectCountByPaypalButtonId(ByVal productPaypalButtonId As Integer) As Integer
        Return SelectCount(New CCriteriaList("ProductPaypalButtonId", productPaypalButtonId))
    End Function
    Protected Function SelectCountByIsActive(ByVal productIsActive As Boolean) As Integer
        Return SelectCount(New CCriteriaList("ProductIsActive", productIsActive))
    End Function
    Protected Function SelectCountByScribeId(ByVal productScribeId As Byte) As Integer
        Return SelectCount(New CCriteriaList("ProductScribeId", productScribeId))
    End Function
    Protected Function SelectCountByImageScribeId(ByVal productImageScribeId As Byte) As Integer
        Return SelectCount(New CCriteriaList("ProductImageScribeId", productImageScribeId))
    End Function
    Protected Function SelectCountByVimeoId(ByVal productVimeoId As Integer) As Integer
        Return SelectCount(New CCriteriaList("ProductVimeoId", productVimeoId))
    End Function
    Protected Function SelectCountByYouTubeId(ByVal productYouTubeId As String) As Integer
        Return SelectCount(New CCriteriaList("ProductYouTubeId", productYouTubeId))
    End Function
    Protected Function SelectCountBySmashwordsId(ByVal productSmashwordsId As Integer) As Integer
        Return SelectCount(New CCriteriaList("ProductSmashwordsId", productSmashwordsId))
    End Function
    Protected Function SelectCountByAmazonId(ByVal productAmazonId As String) As Integer
        Return SelectCount(New CCriteriaList("ProductAmazonId", productAmazonId))
    End Function
    Protected Function SelectCountByCSBookId(ByVal productCSBookId As Integer) As Integer
        Return SelectCount(New CCriteriaList("ProductCSBookId", productCSBookId))
    End Function
    Protected Function SelectCountByCSBook2Id(ByVal productCSBook2Id As Integer) As Integer
        Return SelectCount(New CCriteriaList("ProductCSBook2Id", productCSBook2Id))
    End Function
    Protected Function SelectCountByCSBook3Id(ByVal productCSBook3Id As Integer) As Integer
        Return SelectCount(New CCriteriaList("ProductCSBook3Id", productCSBook3Id))
    End Function
    Protected Function SelectCountByYouTubePlaylistId(ByVal productYouTubePlaylistId As String) As Integer
        Return SelectCount(New CCriteriaList("ProductYouTubePlaylistId", productYouTubePlaylistId))
    End Function
    Protected Function SelectCountByVimeoChannelId(ByVal productVimeoChannelId As String) As Integer
        Return SelectCount(New CCriteriaList("ProductVimeoChannelId", productVimeoChannelId))
    End Function

    'Transactional
    Friend Function SelectByTypeId(ByVal productTypeId As Byte, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductTypeId", productTypeId), tx)
    End Function
    Friend Function SelectBySpeakerId(ByVal productSpeakerId As Byte, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductSpeakerId", productSpeakerId), tx)
    End Function
    Friend Function SelectBySpeaker2Id(ByVal productSpeaker2Id As Byte, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductSpeaker2Id", productSpeaker2Id), tx)
    End Function
    Friend Function SelectByLanguageId(ByVal productLanguageId As Byte, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductLanguageId", productLanguageId), tx)
    End Function
    Friend Function SelectByLocationId(ByVal productLocationId As Byte, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductLocationId", productLocationId), tx)
    End Function
    Friend Function SelectByBelongsToProductId(ByVal productBelongsToProductId As Integer, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductBelongsToProductId", productBelongsToProductId), tx)
    End Function
    Friend Function SelectByPaypalButtonId(ByVal productPaypalButtonId As Integer, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductPaypalButtonId", productPaypalButtonId), tx)
    End Function
    Friend Function SelectByIsActive(ByVal productIsActive As Boolean, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductIsActive", productIsActive), tx)
    End Function
    Friend Function SelectByScribeId(ByVal productScribeId As Byte, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductScribeId", productScribeId), tx)
    End Function
    Friend Function SelectByImageScribeId(ByVal productImageScribeId As Byte, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductImageScribeId", productImageScribeId), tx)
    End Function
    Friend Function SelectByVimeoId(ByVal productVimeoId As Integer, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductVimeoId", productVimeoId), tx)
    End Function
    Friend Function SelectByYouTubeId(ByVal productYouTubeId As String, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductYouTubeId", productYouTubeId), tx)
    End Function
    Friend Function SelectBySmashwordsId(ByVal productSmashwordsId As Integer, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductSmashwordsId", productSmashwordsId), tx)
    End Function
    Friend Function SelectByAmazonId(ByVal productAmazonId As String, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductAmazonId", productAmazonId), tx)
    End Function
    Friend Function SelectByCSBookId(ByVal productCSBookId As Integer, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductCSBookId", productCSBookId), tx)
    End Function
    Friend Function SelectByCSBook2Id(ByVal productCSBook2Id As Integer, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductCSBook2Id", productCSBook2Id), tx)
    End Function
    Friend Function SelectByCSBook3Id(ByVal productCSBook3Id As Integer, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductCSBook3Id", productCSBook3Id), tx)
    End Function
    Friend Function SelectByYouTubePlaylistId(ByVal productYouTubePlaylistId As String, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductYouTubePlaylistId", productYouTubePlaylistId), tx)
    End Function
    Friend Function SelectByVimeoChannelId(ByVal productVimeoChannelId As String, tx As IDbTransaction) As CProductList
        Return SelectWhere(New CCriteriaList("ProductVimeoChannelId", productVimeoChannelId), tx)
    End Function
#End Region

#Region "Static - Cache Implementation"
    Public Shared Property Cache() As CProductList
        Get
            Cache = CType(CCache.Get(CACHE_KEY), CProductList)
            If IsNothing(cache) Then
                SyncLock (CACHE_KEY)
                    Cache = CType(CCache.Get(CACHE_KEY), CProductList)
                    If IsNothing(cache) Then
                        Cache = LoadCache()
                        CProduct.Cache = Cache
                    End If
                End SyncLock
            End If
            Return cache
        End Get
        Set(ByVal value As CProductList)
            SetCache(value)
        End Set
    End Property

    'Change Management:
    'Clone, modify, and then replace the cache (threadsafe for anything iterating the collection)
    'Note that internal indices are dicarded each time unless handled in constructor and add/remove overrides
    Protected Overrides Sub CacheDelete()
        If CacheIsNull Then Exit Sub
        SyncLock (CACHE_KEY)
            Dim temp As CProductList = New CProductList(Cache)
            Dim size As Integer = temp.Count
            temp.Remove(Me)
            If size = temp.Count Then 'Remove might fail If cache was refreshed with New instances. Use old index                    
                temp.Remove(CacheGetById(temp))
            End If
            SetCache(temp)
        End SyncLock
    End Sub
    Protected Overrides Sub CacheInsert()
        If CacheIsNull Then Exit Sub
        SyncLock (CACHE_KEY)
            Dim temp As CProductList = New CProductList(Cache)
            temp.Add(Me)
            SetCache(temp)
        End SyncLock
    End Sub
    Protected Overrides Sub CacheUpdate()
        If CacheIsNull Then Exit Sub
        SyncLock (CACHE_KEY)
            Dim temp As CProductList = New CProductList(Cache)
            If Not temp.Contains(Me) Then
                temp.Remove(CacheGetById(temp))
                temp.Add(Me)
            End If
            SetCache(temp)
        End SyncLock
    End Sub
    Protected Overrides Sub CacheClear()
        Cache = Nothing
    End Sub
    Public Shared ReadOnly Property CacheIsNull() As Boolean
        Get
            Return IsNothing(CCache.Get(CACHE_KEY))
        End Get
    End Property
#End Region


#Region "Audit Trail"
    Protected Overrides Function OriginalState(ByVal txOrNull As IDbTransaction) As SchemaAudit.CBaseDynamicAudited
        Return New CProduct(Me.DataSrc, Me.ProductId, txOrNull)
    End Function
#End Region


End Class